//
// Author: TOKUMOTO Susumu
#region Using Directives

using System;
using Microsoft.Practices.ComponentModel;
using Microsoft.Practices.RecipeFramework;
using Microsoft.Practices.RecipeFramework.Services;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using EnvDTE;
using EnvDTE80;
using WiGO.RCX.PF.Actions.lib;
using Microsoft.Practices.RecipeFramework.Library;

#endregion

namespace WiGO.RCX.PF.Actions
{
    class ImportProjectAction : Action
    {
        #region Input Properties

        [Input]
        public string SourcePath
        {
            get { return sourcePath; }
            set { sourcePath = value; }
        } string sourcePath;

        [Input]
        public Project TargetFolder
        {
            get { return targetFolder; }
            set { targetFolder = value; }
        } Project targetFolder;

        [Input]
        public bool CopyProject
        {
            get { return copyProject; }
            set { copyProject = value; }
        } bool copyProject;

        #endregion

        #region Output Properties
        [Output]
        public string Result
        {
            get { return actionResult; }
            set { actionResult = value; }
        } string actionResult;

        #endregion

        #region IAction Members

        private List<string> copiedFiles = new List<string>();

        public override void Execute()
        {
            SolutionFolder slfolder = (SolutionFolder)targetFolder.Object;

            if (copyProject)
            {
                string sourceDirectory = Path.GetDirectoryName(sourcePath);
                DTE vs = GetService<DTE>(true);
                Solution2 currentSolution = vs.Solution as Solution2;
                String destPath = PSFActionUtility.FindProjectAbsolutePath(currentSolution, targetFolder);
                destPath = destPath + Path.DirectorySeparatorChar + Path.GetFileName(sourceDirectory);

                CopyContentsFromGP2Prj.CopyContents(sourceDirectory, "*", destPath);
                slfolder.AddFromFile(destPath + "\\" + Path.GetFileName(sourcePath));
            }
            else
            {
                slfolder.AddFromFile(sourcePath);
            }
        }

        public override void Undo()
        {
            // remove files
        }

        #endregion
    }
}
